
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>杆塔管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/dgfp_39_hz/statics/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/dgfp_39_hz/statics/table/bootstrap-table.min.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/jquery-3.2.1.min.js"></script>

    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/ajaxfileupload.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/table/bootstrap-table.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <link rel="stylesheet" href="css/sweetalert.css">
    <script type="text/javascript" src="css/sweetalert.min.js"></script>
    <script type="${pageContext.request.contextPath}/dgfp_39_hz/assets/js/text/javascript" src="laydate/laydate.js"></script>
    <script type="text/javascript">
        $(function(){
            $('#table').bootstrapTable({
                url: '${pageContext.request.contextPath}/ganta/queryConditionPage',
                columns: [
                    {
                        checkbox:true
                    },{
                        field: 'gtid',
                        title: '杆塔编号'
                    },{
                        field: 'roleline_lx.xlid',
                        title: '线路编号'
                    },
                    {
                        field: 'state',
                        title: '状态（启用/停用）',
                        formatter: function (value, row, index) {
                            if (value == 1) {
                                return "启用";
                            }
                            return "停用";
                        }
                    },{
                        field : 'xx',
                        title : '操作',
                        formatter:function(value,row,index){
                            return "<a href='javascript:upd("+row.id+")'>修改</a>&nbsp;|&nbsp;<a href='javascript:del("+row.id+")'>删除</a>" ;
                        }
                    }
                    ],
                //
                showToggle:true,
                clickToSelect:true,
                singleSelect:true,
                toolbar:"#toolbar",
                method:'post',
                contentType:"application/x-www-form-urlencoded",
                showRefresh:true,
                showColumns:true,
                queryParamsType:'',
                queryParams:queryParams,
                height:360,
                pageList:[5,10,15],
                pageNumber:1,
                pageSize:5,
                pagination:true,
                sidePagination:'server'

            });
        }) ;
        function search(){
            var opt = $("#table").bootstrapTable('getOptions') ;
            var nxlid = $("#nxlid").val() ;
            var state = $("#state").val() ;
            $.post('${pageContext.request.contextPath}/ganta/queryConditionPage',{'xlid':nxlid,'state':state,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                //重新给table绑定数据
                $("#table").bootstrapTable("load",data) ;
            }) ;
        }

        function queryParams (params) {
            var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                'pageSize': params.pageSize,  //页面大小
                'pageNumber': params.pageNumber, //页码
                'xlid':$("#nxlid").val(),
                'state':$("#state").val()
            };
            return temp;
        };


        function save2(){
            //接收数据
            var gtid = $("#gtid").val() ;

            var nxlid = $("#xlid").val() ;//添加的线路

            var nstate=$('input:radio:checked').val();

            $("#myModal").modal("hide") ;

            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#nxlid").val() ;
            var state = $("#state").val() ;
            //
            $.post("${pageContext.request.contextPath}/ganta/add",{"gtid":gtid,"nstate":nstate,"xlid":nxlid,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                alert("添加成功");
                $("#table").bootstrapTable("load",data) ;
            }) ;
        }
        function upd(sid) {
            $("#myModal2").modal("show") ;
            $.post("${pageContext.request.contextPath}/ganta/oneGanta",{"id":sid},function(data){
                console.log(data)
                $("#xggtid").val(data.gtid);
              /*  $('input:radio:checked').val(data.state);*/
            })
        }

        function update() {
            var xgstate =  $('input:radio:checked').val();
            var gtid = $('#xggtid').val();
            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#nxlid").val() ;
            var state = $("#state").val() ;
            $("#myModal2").modal("hide") ;
            $.post("${pageContext.request.contextPath}/ganta/updGanta",{"gtid":gtid,"xgstate":xgstate,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                alert("修改成功");
                $("#table").bootstrapTable("load",data) ;
            }) ;
        }

        var id  ;
        function del(sid){
            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#nxlid").val() ;
            var state = $("#state").val() ;
            id = sid ;
            $.post("${pageContext.request.contextPath}/ganta/delGanta",{"id":id,'xlid':xlid,"state":state,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                $("#table").bootstrapTable("load",data) ;
            })

        }
        function del1() {
            swal({
                    title: "确定删除吗？",
                    text: "你将无法恢复该虚拟文件！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定删除！",
                    cancelButtonText: "取消删除！",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm){
                    if (isConfirm) {
                        swal("删除！", "你的虚拟文件已经被删除。",
                            "success");
                    } else {
                        swal("取消！", "你的虚拟文件是安全的:)",
                            "error");
                    }
                });
        }
    </script>
</head>
<body>
<!--搜索面板-->
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-inline">
            <div class="form-group">
               所属线路编码：<input id="nxlid" type="text" class="form-control" placeholder="搜索内容">
            </div>

            杆塔状态:
            <select id="state" class="form-control">
                <option value="-1">--请选择--</option>
                <option value="1">启用</option>
                <option value="0">停用</option>
            </select>

         <button onclick="search()" type="button" class="btn btn-default">查询</button>
        </form>

    </div>
</div>
<div id="btndiv">
    <button type="button" class="btn" data-toggle="modal"
            data-target="#myModal">增加</button>
    <button type="button" class="btn" data-toggle="modal"
            data-target="#myModal2">修改</button>
    <button type="button" class="btn" onclick="del1()">
        <span class="glyphicon glyphicon-trash"></span>删除
    </button>
</div>
<table id="table" data-classes="table table-hover"></table>

<div class="modal fade" id="myModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">增加杆塔</h4>
            </div>
            <div class="modal-body">
                <!-- form开始 -->
                <form  method="post">
                    <div class="form-group">
                        <label for="gtid" class="col-sm-4 control-label">杆塔编码 *</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="gtid" parsley-trigger="change" parsley-required="true" parsley-minlength="4" parsley-validation-minlength="1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="xlid" class="col-sm-4 control-label">所属线路名称 *</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="xlid" parsley-trigger="change" parsley-required="true" parsley-minlength="4" parsley-type="email" parsley-validation-minlength="1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">启用状态</label>
                        <div class="col-sm-8">
                            <div class="radio radio-transparent">
                                <input type="radio" name="state" id="optionsRadios1" value="1">
                                <label for="optionsRadios1">启用</label>
                            </div>
                            <div class="radio radio-transparent">
                                <input type="radio" name="state" id="optionsRadios2" value="0">
                                <label for="optionsRadios2">停用</label>
                            </div>
                        </div>
                    </div>
                    &nbsp;
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button onclick="save2()" type="button" class="btn btn-primary">提交</button>
                <%--  <input type="submit" value="注册">--%>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal2">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="xgganta">修改杆塔</h4>
            </div>
            <div class="modal-body">
                <!-- form开始 -->
                <form  method="post">
                    <div class="form-group">
                        <label for="gtid" class="col-sm-4 control-label">杆塔编码 *</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" readonly="readonly" id="xggtid"  parsley-trigger="change" parsley-required="true" parsley-minlength="4" parsley-validation-minlength="1">
                        </div>
                    </div>
                <div class="form-group">
                        <label class="col-sm-4 control-label">启用状态</label>
                        <div class="col-sm-8">
                            <div class="radio radio-transparent">
                                <input type="radio" name="state" id="optionsRadios12" value="1">
                                <label for="optionsRadios1">启用</label>
                            </div>
                            <div class="radio radio-transparent">
                                <input type="radio" name="state" id="optionsRadios22" value="0">
                                <label for="optionsRadios2">停用</label>
                            </div>
                        </div>
                    </div>
                </form>
                &nbsp;
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button onclick="update()" type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
